package com.app.util;

public class LevelCodeUtil {
	
	public LevelCodeUtil(){
		
	}
	
	final int DEFAULT_CODE_LEVEL_LEN = 3;
	
	public String getNextCode(String parentCode, String initCode, int codeLevelLength) {
        String currentCode = (Integer.parseInt(initCode) + 1) + "";
        int currentCodeLenght = currentCode.length();
        for (int i = 0; i < codeLevelLength - currentCodeLenght; i++) {
            currentCode = "0" + currentCode;
        }
        return parentCode + currentCode;
    }

    public String getLevelCode(int index) {
    		return getLevelCode(index, DEFAULT_CODE_LEVEL_LEN);
    }
    
    /**
     * 获得某一级的顺序码
     * 例如：index=3    codeLevelLength=3,则返回003,如index=15 codeLevelLength=3，则返回015
     *
     * @param index           顺序码
     * @param codeLevelLength 每级分类的长度
     * @return
     */
    public String getLevelCode(int index, int codeLevelLength) {
        String currentCode = index + "";
        int currentCodeLenght = currentCode.length();
        for (int i = 0; i < codeLevelLength - currentCodeLenght; i++) {
            currentCode = "0" + currentCode;
        }
        return currentCode;
    }
}
